package com.woniu.petkonwledge.service.impl;

import com.woniu.common.entity.DogKonwledge;
import com.woniu.common.entity.ResponseResult;
import com.woniu.petkonwledge.mapper.DogKnowledgeMapper;
import com.woniu.petkonwledge.service.DogKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DogKnowledgeServiceImpl implements DogKnowledgeService {

    @Autowired
    DogKnowledgeMapper dogKonwledgeMapper;
    @Override
    public ResponseResult adddogknowledge(DogKonwledge dogKonwledge) {

        ResponseResult result=new ResponseResult();
        try {
            dogKonwledgeMapper.insertdogknowledge(dogKonwledge);
            result.setCode(200);
            result.setMessage("添加成功");
        }
        catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
            result.setMessage("服务繁忙，请等待...");
        }

        return  result;
    }

    @Override
    public ResponseResult getdogknowledgeAll(){
        ResponseResult result=new ResponseResult();
        try {
            List<DogKonwledge> dogKonwledges = dogKonwledgeMapper.selectdogknowledgeAll();
            result.setCode(200);
            result.setMessage("查询成功");
            if(dogKonwledges.size()==0){
                result.setMessage("空空如也");
            }
            result.setData(dogKonwledges);

        }
        catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
            result.setMessage("服务繁忙，请等待...");
        }

        return  result;
    }
}
